/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller;

import AdminOperations.AdminManageDataBase;
import beans.BackupsBean;
import beans.UserType;
import java.util.ArrayList;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.util.LabelValueBean;

/**
 *
 * @author ABDELMOHSEN
 */
public class GetBackups extends org.apache.struts.action.Action {
    
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        UserType type=(UserType)request.getSession().getAttribute("type");
        if(type==null||!type.equals(UserType.adm)) return mapping.findForward("login");
        AdminManageDataBase model=new AdminManageDataBase();
        BackupsBean bean=(BackupsBean)form;
        Vector<String> backups=model.getAvailableBackups();
        ArrayList<LabelValueBean> list=new ArrayList<LabelValueBean>();
        
        for(int i=0;i<backups.size();i++){
            list.add(new LabelValueBean(backups.get(i), backups.get(i)));
        }
        bean.setBackupsList(list);
        return mapping.findForward("displayDB");
    }
}
